home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / SHADER / SHDR / SHDRFAC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  6.0 KB  |  252 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: ShdrFac.cpp 1.1 1996/07/19 00:15:20 Damien Exp $ */
  3. // Class factories
  4.  
  5. #ifndef __SHDRFAC__
  6. #include "ShdrFac.h"
  7. #endif 
  8.  
  9. #ifndef __RAINBOW__
  10. #include "Rainbow.h"
  11. #endif 
  12.  
  13. #ifndef __CHECKER__
  14. #include "Checker.h"
  15. #endif 
  16.  
  17.  
  18. // ***** ClassFactory *****
  19.   
  20. CheckerClassFactory::CheckerClassFactory() {
  21.   m_cRef=0L;  // just created so no reference used
  22.   return;
  23.   }
  24.  
  25.  
  26. CheckerClassFactory::~CheckerClassFactory() {
  27.   return;
  28.   }
  29.  
  30. // IUnknown methods of CheckerClassFactory                                                
  31. STDMETHODIMP CheckerClassFactory::QueryInterface(REFIID riid, LPVOID FAR* ppv) {
  32.   *ppv=NULL;
  33.  
  34.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  35.       *ppv=(LPVOID)this;
  36.  
  37.   if (*ppv!=NULL) {
  38.     ((LPUNKNOWN)*ppv)->AddRef(); // Add reference if we give a pointer
  39.     return NOERROR;
  40.     }
  41.   else {
  42.       return ResultFromScode(E_NOINTERFACE);
  43.       }
  44.   }
  45.  
  46.  
  47. STDMETHODIMP_(ULONG) CheckerClassFactory::AddRef() {
  48.   return ++m_cRef;
  49.   }
  50.  
  51.  
  52. STDMETHODIMP_(ULONG) CheckerClassFactory::Release() {
  53.   ULONG        UnreleaseRef;
  54.  
  55.   UnreleaseRef=--m_cRef;
  56.  
  57.   if (m_cRef == 0)
  58.       delete this; // No reference left, so delete the CheckerClassFactory
  59.  
  60.   return UnreleaseRef;
  61.   }
  62.  
  63. /*
  64.  * CheckerClassFactory::CreateInstance
  65.  *
  66.  * Parameters:
  67.  *  pUnkOuter       LPUNKNOWN to the controlling IUnknown if we are
  68.  *                  being used in an aggregation.
  69.  *  riid            REFIID identifying the interface the caller
  70.  *                  desires to have for the new object.
  71.  *  ppvObj          LPVOID FAR* in which to store the desired
  72.  *                  interface pointer for the new object.
  73.  *
  74.  * Return Value:
  75.  *  HRESULT         NOERROR if successful, otherwise E_NOINTERFACE
  76.  *                  if we cannot support the requested interface.
  77.  */
  78.  
  79. STDMETHODIMP CheckerClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppvObj) {
  80.   CheckerShader*      pObj = NULL;
  81.   HRESULT       hr;
  82.  
  83.   *ppvObj = NULL;
  84.   hr = ResultFromScode(E_OUTOFMEMORY);
  85.  
  86.   //Verify that a controlling unknown asks for IUnknown
  87.   if (pUnkOuter && !IsEqualIID(riid, IID_IUnknown))
  88.       return ResultFromScode(E_NOINTERFACE);
  89.  
  90.   //Create the object passing function to notify on destruction.
  91.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_I3DExShader))
  92.       pObj = new CheckerShader;
  93.   else
  94.       return ResultFromScode(E_NOINTERFACE);
  95.  
  96.   hr=pObj->QueryInterface(IID_I3DExShader, ppvObj);
  97.  
  98.   //Kill the object if initial creation failed.
  99.   if (FAILED(hr))
  100.       delete pObj;
  101.   else
  102.       global_count_Obj++;
  103.  
  104.   return hr;
  105.   }
  106.  
  107.  
  108. /*
  109.  * CheckerClassFactory::LockServer
  110.  *
  111.  * Purpose:
  112.  *  Increments or decrements the lock count of the DLL.  If the
  113.  *  lock count goes to zero and there are no objects, the DLL
  114.  *  is allowed to unload.  See DllCanUnloadNow in "Shadrdll.cpp".
  115.  *
  116.  * Parameters:
  117.  *  fLock           BOOL specifying whether to increment or
  118.  *                  decrement the lock count.
  119.  *
  120.  * Return Value:
  121.  *  HRESULT         NOERROR always.
  122.  */
  123.  
  124. STDMETHODIMP CheckerClassFactory::LockServer(BOOL fLock) {
  125.   if (fLock)
  126.       global_count_Lock++;
  127.   else
  128.       global_count_Lock--;
  129.  
  130.   return NOERROR;
  131.   }
  132.  
  133.  
  134.   
  135. // ****** Class Factory *****
  136.  
  137. //------------------------------------------------------------------------
  138.  
  139. RainbowClassFactory::RainbowClassFactory() {
  140.   m_cRef=0L;
  141.   return;
  142.   }
  143.  
  144.  
  145. RainbowClassFactory::~RainbowClassFactory() {
  146.   return;
  147.   }
  148.  
  149. HRESULT RainbowClassFactory::QueryInterface(REFIID riid, LPVOID FAR* ppv) {
  150.   *ppv=NULL;
  151.  
  152.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  153.       *ppv=(LPVOID)this;
  154.  
  155.   if (*ppv!=NULL) {
  156.     ((LPUNKNOWN)*ppv)->AddRef();
  157.     return NOERROR;
  158.     }
  159.   else {
  160.       return ResultFromScode(E_NOINTERFACE);
  161.       }
  162.   }
  163.  
  164.  
  165. ULONG RainbowClassFactory::AddRef() {
  166.   return ++m_cRef;
  167.   }
  168.  
  169.  
  170. ULONG RainbowClassFactory::Release() {
  171.   ULONG        UnreleaseRef;
  172.  
  173.   UnreleaseRef=--m_cRef;
  174.  
  175.   if (m_cRef == 0) 
  176.        delete this;
  177.  
  178.   return UnreleaseRef;
  179.   }
  180.  
  181. /*
  182.  * ShaderClassFactory::CreateInstance
  183.  *
  184.  * Parameters:
  185.  *  pUnkOuter       LPUNKNOWN to the controlling IUnknown if we are
  186.  *                  being used in an aggregation.
  187.  *  riid            REFIID identifying the interface the caller
  188.  *                  desires to have for the new object.
  189.  *  ppvObj          LPVOID FAR* in which to store the desired
  190.  *                  interface pointer for the new object.
  191.  *
  192.  * Return Value:
  193.  *  HRESULT         NOERROR if successful, otherwise E_NOINTERFACE
  194.  *                  if we cannot support the requested interface.
  195.  */
  196.  
  197. HRESULT RainbowClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppvObj) {
  198.   RainbowShader*      pObj = NULL;
  199.   HRESULT       hr;
  200.  
  201.   *ppvObj = NULL;
  202.   hr = ResultFromScode(E_OUTOFMEMORY);
  203.  
  204.   //Verify that a controlling unknown asks for IUnknown
  205.   if (pUnkOuter && !IsEqualIID(riid, IID_IUnknown))
  206.       return ResultFromScode(E_NOINTERFACE);
  207.  
  208.   //Create the object passing function to notify on destruction.
  209.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_I3DExShader))
  210.       pObj = new RainbowShader;
  211.   else
  212.       return ResultFromScode(E_NOINTERFACE);
  213.  
  214.   hr=pObj->QueryInterface(IID_I3DExShader, ppvObj);
  215.  
  216.   //Kill the object if initial creation failed.
  217.   if (FAILED(hr))
  218.       delete pObj;
  219.   else
  220.       global_count_Obj++;
  221.  
  222.   return hr;
  223.   }
  224.  
  225.  
  226. /*
  227.  * ShaderClassFactory::LockServer
  228.  *
  229.  * Purpose:
  230.  *  Increments or decrements the lock count of the DLL.  If the
  231.  *  lock count goes to zero and there are no objects, the DLL
  232.  *  is allowed to unload.  See DllCanUnloadNow.
  233.  *
  234.  * Parameters:
  235.  *  fLock           BOOL specifying whether to increment or
  236.  *                  decrement the lock count.
  237.  *
  238.  * Return Value:
  239.  *  HRESULT         NOERROR always.
  240.  */
  241.  
  242. HRESULT RainbowClassFactory::LockServer(BOOL fLock) {
  243.   if (fLock)
  244.       global_count_Lock++;
  245.   else
  246.       global_count_Lock--;
  247.  
  248.   return NOERROR;
  249.   }
  250.  
  251.  
  252.